package cn.lysj.framework.coupon.repository;

import cn.lysj.framework.base.BaseRepository;
import cn.lysj.framework.coupon.domain.BirthdayCouponConfig;
import cn.lysj.framework.coupon.vo.BirthdayCouponToStoreVo;
import cn.lysj.framework.coupon.vo.BirthdayCouponToUserVo;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author zwj
 * @description 生日优惠券配置数据处理层
 * @create 2019-01-16 09:39:10
 **/
public interface BirthdayCouponConfigRepository extends BaseRepository<BirthdayCouponConfig> {
    //给商家看的生日优惠券信息
    @Query(value = "select new cn.lysj.framework.coupon.vo.BirthdayCouponToStoreVo(a.id,a.couponId,b.name,b.fullReductionMoney,b.discountMoney,b.shareType,b.share,b.deadlineType,b.useBeginDate,b.useEndDate,b.validPeriod) " +
            "from BirthdayCouponConfig a,Coupon b where a.couponId = b.id and b.delFlag = 1 and a.storeId = ?1 order by a.createTime desc ")
    List<BirthdayCouponToStoreVo> findBirthdayCouponToStoreVo(String storeId);

    List<BirthdayCouponConfig> findByStoreId(String storeId);

    //给用户看的可以领取的优惠券
    @Query(value = "select new cn.lysj.framework.coupon.vo.BirthdayCouponToUserVo(a.id,a.couponId,b.name,b.fullReductionMoney,b.discountMoney,b.shareType,b.share,b.validPeriod,b.eventTitle,b.eventInfo,b.eventImg) " +
            "from BirthdayCouponConfig a,Coupon b where a.couponId = b.id and b.delFlag = 1 and a.storeId = ?1 order by a.createTime")
    List<BirthdayCouponToUserVo> findBirthdayCouponToUserVo(String storeId);

}
